package com.fubowen.lepton.extension

import android.content.Context
import android.view.Window
import android.view.WindowManager
import androidx.annotation.IntRange


fun getStatusBarHeight(context: Context): Int {
    var statusBarHeight = 0
    val resources = context.resources
    val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
    if (resourceId > 0) {
        statusBarHeight = resources.getDimensionPixelSize(resourceId)
    }
    return statusBarHeight
}

fun Window.setScreenBrightness(@IntRange(-1, 255) value: Int) {
    val lp = this.attributes
    if (value < 0) {
        lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
    } else {
        lp.screenBrightness = value / 255f
    }
    this.attributes = lp
}
